import pygame
from MainWindow import MainWindow
from Person import Person
from S_Wall import S_Wall
from D_Wall import D_Wall
from Door import Door
from Door_Person import Door_Person
from Spikes import Spikes

class MainGame_two(MainWindow):
    def __init__(self):
        super().__init__()

        self.person = Person(150, 500)  # 人物初始化
        self.S_Walls.extend([
            S_Wall(0, 0, 1000, 150),
            S_Wall(0, 150, 100, 350),

            S_Wall(900, 150, 100, 350),

            S_Wall(0, 500, 360, 300),  # 地面调整到750高度
            S_Wall(600, 500, 750, 300),  # 地面调整到750高度

            S_Wall(200, 488, 40, 12),  # 地面调整到750高度
            S_Wall(240, 476, 40, 24),  # 地面调整到750高度
            S_Wall(280, 464, 40, 36),  # 地面调整到750高度

            ])  # 静态墙初始化 [x,y]

        self.D_Walls.extend([
            D_Wall(360, 500, 240, 300, 'x', 8, True, 40),
        ])

        self.Spikes.extend([
            Spikes(240, 476),
            Spikes(700, 500)
        ])

        self.all_sprites.add(self.person)
        for wall in self.S_Walls:
            self.obstacles.add(wall)
        for wall in self.D_Walls:
            self.D_obstacles.add(wall)

        self.door = Door(850, 500)  # 出口初始化
        self.door_person = Door_Person(self.door.rect.x, self.door.rect.y)  # 出口动画初始化
    def StartGame(self):
        super().Start()
        while True:
            dt = self.clock.tick(60) / 1000  # 获取delta time用于平滑移动
            self.GetEvent()
            self.update(dt)
            self.render()
            self.brith()
            pygame.display.flip()
            # 后续添加判断人门图片是否存在，然后结束本关卡。
            if not self.door_person.alive:
                break

    # 渲染窗口
    def render(self):
        super().render()
        for d_wall in self.D_obstacles:
            if d_wall.alive == True:
                d_wall.move_img_display(self.window)
            else:
                if d_wall.visible == False:
                    self.window.blit(d_wall.image, d_wall.rect)
                    d_wall.wall_move('x', -3)

        if not self.person.rect.colliderect(self.door.rect):
            self.all_sprites.draw(self.window)
            self.door.Door_display(self.window)
        else:
            self.reached_door = True
            self.door_person.img_move('y', 3)
            self.door_person.move_img_display(self.window)



